﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NP.Model;


namespace NP.BL
{
    public class ProductsTopDiscounts
    {
        public ProductTopDiscountViewModel[] GetTopDiscouts()
        {
            using (var db = new NorthwindDataClassesDataContext())
            {
                var discounts = db.Order_Details.ToArray()
                    .Select(n => new ProductTopDiscountViewModel
                    {
                        ProductID = n.ProductID,
                        Product = n.Product.ProductName,
                        UnitPrice = n.UnitPrice,
                        Quantity = n.Quantity,
                        Discout = (decimal)n.Discount,
                        TotalDiscout = n.UnitPrice * n.Quantity * (decimal)n.Discount
                    }).OrderByDescending(n => n.TotalDiscout).Take(10).ToArray();


                return discounts;
            }
        }
    }
}
